<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
        // 受控组件：类似于vue 的双向数据绑定，表单控件值一变化就更新状态
    class Login extends React.Component {
        handleSubmit = e => {
            e.preventDefault(); // 阻止默认行为
            alert(`用户名：${this.username.value}密码：${this.password.value}`)
        }
        render() {
            return (
                <form onSubmit={this.handleSubmit}>
                    用户名：<input ref={c => this.username = c} type="text" name="username" />
                    密码：<input ref={c => this.password = c} type="password" name="password" />
                    <button>login</button>
                </form>
            )
        }
    }
    
    // 渲染dom
    ReactDOM.render(<Login />, document.getElementById('app'))
    </script>

</body>
</html>